package cn.edu.neusoft.neufooddemo.fragment;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cn.edu.neusoft.neufooddemo.R;
import cn.edu.neusoft.neufooddemo.adapter.CollectAdapter;
import cn.edu.neusoft.neufooddemo.bean.CollectInfo;
import cn.edu.neusoft.neufooddemo.listener.RetrofitListener;
import cn.edu.neusoft.neufooddemo.model.UserModel;



public class CollectFoodFragment extends BaseFragment implements RetrofitListener<List<CollectInfo>>{

    private RecyclerView collect_rv;
    private CollectAdapter adapter;
    private UserModel userModel;

    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        setLayout_file(R.layout.fragment_container);
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    void initViews() {
        collect_rv = (RecyclerView) view.findViewById(R.id.rv);
        collect_rv.setLayoutManager(new LinearLayoutManager(context));
    }

    @Override
    void initEvents() {

    }

    void initData() {
        userModel = new UserModel();
        userModel.getAllUserCollection(getUser_id(), "1",this);
    }

    @Override
    public void onSuccess(List<CollectInfo> collectInfos, int flag) {
        adapter = new CollectAdapter(context, collectInfos, R.layout.cardview_collect);
        collect_rv.setAdapter(adapter);
    }

    @Override
    public void onFail() {
            showToast("网络错误");
    }
}
